package com.alibaba.citrus.cr.unified.inventory.contants;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * @author yifei
 * @since 2024/3/7
 */
@Getter
@AllArgsConstructor
public enum MessageEventCodeEnum {
    CREATE("CREATE_EVENT", "创建"),
    EDIT("EDIT_EVENT", "修改"),
    ENABLE("ENABLE_EVENT", "启用"),
    FORBID("FORBID_EVENT", "禁用"),
    SUBMIT("SUBMIT_EVENT","提交"),
    CLOSED("CLOSED_EVENT","关闭");

    private final String code;
    private final String name;


    /**
     * 根据code获取枚举
     *
     * @param code code
     * @return 返回
     */
    public static MessageEventCodeEnum getEnum(String code) {
        if (code == null) {
            return null;
        }
        for (MessageEventCodeEnum eventCode : MessageEventCodeEnum.values()) {
            if (eventCode.getCode().equals(code)) {
                return eventCode;
            }
        }
        return null;
    }

    /**
     * 检查code是否存在
     *
     * @param code code
     * @return 是否存在
     */
    public static boolean isExist(String code){
        if (StringUtils.isBlank(code)){
            return false;
        }
        MessageEventCodeEnum anEnum = getEnum(code);
        return anEnum != null;
    }

    /**
     * 根据code获取对应的描述
     *
     * @param code code
     * @return 返回
     */
    public static String getNameByCode(String code) {
        MessageEventCodeEnum statusEnum = getEnum(code);
        if (statusEnum == null){
            return "";
        }
        return statusEnum.getName();
    }



    public String getEnumName() {
        return this.name;
    }
}
